#ifndef BINARY_OR_HH_
# define BINARY_OR_HH_

# include "common.hh"
# include "tbb/task_scheduler_init.h"
# include "tbb/blocked_range2d.h"
# include <SDL/SDL.h>

class BinOr
{
  Uint32	*img1, *img2;

 public:
  BinOr	 (Uint32	*img1_,
	  Uint32	*img2_)
    : img1(img1_),
      img2(img2_)
    {
    }

  void operator() (const tbb::blocked_range2d<int>& r) const
  {
    for (int i = r.rows().begin(); i!= r.rows().end(); ++i)
      {
	for (int j = r.cols().begin(); j!= r.cols().end(); ++j)
	  {
	    Uint32 coul1 = img1[i * WIDTH + j];
	    Uint32 coul2 = img2[i * WIDTH + j];

	    img1[i * WIDTH + j] = coul1 | coul2;
	  }
      }
    if (img1 == global_screen->pixels)
      {
	tbb::spin_mutex::scoped_lock lock;

	lock.acquire(global_screen_mutex);

	SDL_UpdateRect(global_screen,
		       r.cols().begin(),
		       r.rows().begin(),
		       r.cols().end() - r.cols().begin(),
		       r.rows().end() - r.rows().begin());

	lock.release();
      }
  }
};

#endif /* !BINARY_OR_HH_ */
